package com.copa.l2287;

/**
 * @author copa
 * @createDate 2023-01-13 15:13
 * @function 数组计数法
 */
public class Test2 {

    public int rearrangeCharacters(String s, String target) {
        int count = Integer.MAX_VALUE;
        int[] targetArray = new int[26];
        char[] tempTarget = target.toCharArray();
        for (char c : tempTarget) {
            targetArray[c - 'a']++;
        }
        int[] sArray = new int[26];
        char[] sTemp = s.toCharArray();
        for (char c : sTemp) {
            sArray[c - 'a']++;
        }
        for (int i = 0; i < 26; i++) {
            if (targetArray[i] == 0) {
                continue;
            }
            count = Math.min(sArray[i] / targetArray[i], count);
            if (count == 0) {
                return count;
            }
        }
        return count;
    }

    public static void main(String[] args) {
        String s = "ilovecodingonleetcode";
        String target = "code";
        System.out.println(new Test2().rearrangeCharacters(s, target));
    }
}
